using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.AccountsDomain;
using ShivamEMR.Model.DataInterfaces.AccountsDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Accounts.Controllers
{   
    public class FinancialYearController : Controller
    {
		private readonly IFinancialYearRepository financialyearRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public FinancialYearController()// : this(new FinancialYearRepository())
        {
            this.financialyearRepository = Registry.RepositoryFactory.GetFinancialYearRepository();
        }

        public FinancialYearController(IFinancialYearRepository financialyearRepository)
        {
			this.financialyearRepository = financialyearRepository;
        }

        //
        // GET: /FinancialYear/

        public ViewResult Index()
        {
            return View(financialyearRepository.All);//Including(financialyear => financialyear.Transactions, financialyear => financialyear.Vouchers));
        }

        //
        // GET: /FinancialYear/Details/5

        public ViewResult Details(int id)
        {
            return View(financialyearRepository.Find(id));
        }

        //
        // GET: /FinancialYear/Create

        public ActionResult Create()
        {
            var fy = new FinancialYear() { StartDate=DateTime.Now, EndDate=DateTime.Now };
            return View(fy);
        } 

        //
        // POST: /FinancialYear/Create

        [HttpPost]
        public ActionResult Create(FinancialYear financialyear)
        {
            if (ModelState.IsValid) {
                financialyearRepository.InsertOrUpdate(financialyear);
                financialyearRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /FinancialYear/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(financialyearRepository.Find(id));
        }

        //
        // POST: /FinancialYear/Edit/5

        [HttpPost]
        public ActionResult Edit(FinancialYear financialyear)
        {
            if (ModelState.IsValid) {
                financialyearRepository.InsertOrUpdate(financialyear);
                financialyearRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /FinancialYear/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(financialyearRepository.Find(id));
        }

        //
        // POST: /FinancialYear/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var fy = financialyearRepository.Find(id);
            financialyearRepository.Delete(fy);
            financialyearRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

